namespace QMVnSoft.Invoices
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCTSXPause : FormControl
    {
        private BtnControl btnCancel;
        private BtnControl btnDelete;
        private BtnControl btnSave;
        private IContainer components;
        private GBoxControl gBoxControl1;
        private object is_MasterKey;
        private LabelControl lblNgay;
        private CTSXDataAccess oMethod = new CTSXDataAccess();
        private TextDate txtNgay;

        public FormCTSXPause()
        {
            this.InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.oMethod.CtSX_Pause_Delete(this.MasterKey) != 1)
            {
                MessageBox.Show("Không thể xóa được!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                base.Close();
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            this.OnSave();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            //ComponentResourceManager manager = new ComponentResourceManager(typeof(FormCTSXPause));
            this.txtNgay = new TextDate();
            this.lblNgay = new LabelControl();
            this.btnCancel = new BtnControl();
            this.btnDelete = new BtnControl();
            this.gBoxControl1 = new GBoxControl();
            this.btnSave = new BtnControl();
            this.gBoxControl1.SuspendLayout();
            base.SuspendLayout();
            this.txtNgay.DateTimeFormat = TextDate.DateTimeFormatType.Date;
            this.txtNgay.Font = new Font("Arial", 8.25f);
            this.txtNgay.InsertKeyMode = InsertKeyMode.Overwrite;
            this.txtNgay.Location = new Point(0x66, 0x22);
            this.txtNgay.Mask = "00/00/0000";
            this.txtNgay.Name = "txtNgay";
            this.txtNgay.OldValue = null;
            this.txtNgay.Size = new Size(0x4e, 20);
            this.txtNgay.TabIndex = 0;
//            this.txtNgay.Value = null;//manager.GetObject("txtNgay.Value");
            this.lblNgay.AutoSize = true;
            this.lblNgay.Font = new Font("Arial", 8.25f);
            this.lblNgay.Location = new Point(0x3e, 0x25);
            this.lblNgay.Name = "lblNgay";
            this.lblNgay.Size = new Size(0x20, 14);
            this.lblNgay.TabIndex = 4;
            this.lblNgay.Text = "Ngày";
            this.btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            //this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Font = new Font("Arial", 8.25f);
            this.btnCancel.Location = new Point(200, 0x74);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x5e, 0x17);
            this.btnCancel.TabIndex = 3;
            this.btnCancel.Text = "&Quay ra";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.btnDelete.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnDelete.Font = new Font("Arial", 8.25f);
            this.btnDelete.Location = new Point(0x6a, 0x74);
            this.btnDelete.Name = "btnDelete";
            this.btnDelete.Size = new Size(0x5e, 0x17);
            this.btnDelete.TabIndex = 2;
            this.btnDelete.Text = "&Xóa";
            this.btnDelete.UseVisualStyleBackColor = true;
            this.btnDelete.Click += new EventHandler(this.btnDelete_Click);
            this.gBoxControl1.Controls.Add(this.txtNgay);
            this.gBoxControl1.Controls.Add(this.lblNgay);
            this.gBoxControl1.Font = new Font("Arial", 8.25f);
            this.gBoxControl1.Location = new Point(12, 12);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new Size(0x11a, 0x59);
            this.gBoxControl1.TabIndex = 0;
            this.gBoxControl1.TabStop = false;
            this.btnSave.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            this.btnSave.Font = new Font("Arial", 8.25f);
            this.btnSave.Location = new Point(12, 0x74);
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new Size(0x5e, 0x17);
            this.btnSave.TabIndex = 1;
            this.btnSave.Text = "&Lưu";
            this.btnSave.UseVisualStyleBackColor = true;
            this.btnSave.Click += new EventHandler(this.btnSave_Click);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.CancelButton = this.btnCancel;
            base.ClientSize = new Size(0x132, 0x97);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.btnSave);
            base.Controls.Add(this.btnDelete);
            base.Controls.Add(this.gBoxControl1);
            //base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "FormCtSXPause";
            this.Text = "Dừng lệnh sản xuất";
            this.gBoxControl1.ResumeLayout(false);
            this.gBoxControl1.PerformLayout();
            base.ResumeLayout(false);
        }

        private void OnSave()
        {
            if (this.txtNgay.Value.Equals(DBNull.Value))
            {
                MessageBox.Show("Chưa nhập ngày dừng lệnh sản xuất!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (this.oMethod.CtSX_Pause_Save(this.MasterKey, this.txtNgay.Value) != 1)
            {
                MessageBox.Show("Không lưu được dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                base.Close();
            }
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.Return))
            {
                this.OnSave();
                return true;
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }

        public object MasterKey
        {
            get
            {
                return this.is_MasterKey;
            }
            set
            {
                this.is_MasterKey = value;
                this.txtNgay.Value = this.oMethod.CtSX_Pause_Get(this.is_MasterKey);
            }
        }
    }
}

